using System;

namespace Drill.Core.Utilities
{
    /// <summary>
    /// Provides utilities that deal with the disposal of resources and the <see cref="IDisposable"/> interface.
    /// </summary>
    public static class DisposeUtility
    {
        /// <summary>
        /// Disposes the specified object if it implements the <see cref="IDisposable"/> interface.
        /// </summary>
        /// <param name="obj">The obj to be disposed, if possible.</param>
        public static void DisposeIfPossible(object obj)
        {
            if (null == obj)
            {
                return;
            }

            IDisposable disposable = obj as IDisposable;

            if (null != disposable)
            {
                disposable.Dispose();
            }
        }
    }
}